home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tsptp.zip / TSBENCH.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-09  |  4KB  |  144 lines

  1. (******************************************************************************)
  2. (*                                 TSBENCH.PAS                                *)
  3. (*                                                                            *)
  4. (*  Routines for internal timer used by the Pascal benchmarks.                *)
  5. (*                                                                            *)
  6. (******************************************************************************)
  7.  
  8. IMPLEMENTATION UNIT TSBench;
  9.  
  10.   IMPORT Lib;
  11.  
  12.   VAR
  13.     Hours,
  14.     Minutes,
  15.     Seconds,
  16.     Hundredths  : WORD;
  17.  
  18.     NullLoops,
  19.     BenchLoops  : BmCounter;
  20.  
  21.     NullLoopTime,
  22.     BenchLoopTime,
  23.     StartTime,
  24.     NullTime,
  25.     BenchTime   : BmTimeT;
  26.  
  27.  
  28. (** STARTTIMER ****************************************************************
  29.  *
  30.  *  Synopsis:
  31.  *
  32.  *    StartTimer;
  33.  *
  34.  *  Description:
  35.  *
  36.  *    StartTime starts the benchmark timer.
  37.  *)
  38.  
  39.   PROCEDURE StartTimer;
  40.   BEGIN
  41.     Lib.GetTime(Hours, Minutes, Seconds, Hundredths);
  42.     StartTime := (((((Hours * 60)+Minutes)*60)+Seconds)*100)+Hundredths;
  43.   END;
  44.  
  45.  
  46. (** NULLTIMESUP ***************************************************************
  47.  *
  48.  *  Synopsis:
  49.  *
  50.  *    NullTimesUp;
  51.  *
  52.  *  Description:
  53.  *
  54.  *    NullTimesUp stops the timer when the NULL timing loop is complete.
  55.  *)
  56.  
  57.   FUNCTION NullTimesUp{: BOOLEAN};
  58.   BEGIN
  59.     Lib.GetTime(Hours, Minutes, Seconds, Hundredths);
  60.     NullTime    := ((((((Hours * 60)+Minutes)*60)+Seconds)*100)+Hundredths)-StartTime;
  61.     NullLoops   := NullLoops + 1;
  62.     NullTimesUp := (NullTime >= NullLoopTime);
  63.   END;
  64.  
  65.  
  66. (** BENCHTIMESUP **************************************************************
  67.  *
  68.  *  Synopsis:
  69.  *
  70.  *    BenchTimesUp;
  71.  *
  72.  *  Description:
  73.  *
  74.  *    BenchTimesUp stops the timer when the NULL timing loop is complete.
  75.  *)
  76.  
  77.   FUNCTION BenchTimesUp{: BOOLEAN};
  78.   BEGIN
  79.     Lib.GetTime(Hours, Minutes, Seconds, Hundredths);
  80.     BenchTime     := ((((((Hours * 60)+Minutes)*60)+Seconds)*100)+Hundredths)-StartTime;
  81.     BenchLoops    := BenchLoops + 1;
  82.     BenchTimesUp  := (BenchTime >= BenchLoopTime);
  83.   END;
  84.  
  85.  
  86. (** REPORTTIMES ***************************************************************
  87.  *
  88.  *  Synopsis:
  89.  *
  90.  *    ReportTimes;
  91.  *
  92.  *  Description:
  93.  *
  94.  *    ReportTimes reports the benchmark times and stats.  Note that the
  95.  *    calculated results for LoopOverhead, TotalTime and Loops per second
  96.  *    are prone to any floating point errors.  Therefore you may wish to
  97.  *    check these results manually.
  98.  *)
  99.  
  100.   PROCEDURE ReportTimes;
  101.     VAR
  102.       RLoopOverhead  : REAL;
  103.       RTotalTime     : REAL;
  104.   BEGIN
  105.     RLoopOverhead := (NullTime/NullLoops)*BenchLoops;
  106.     RTotalTime    := BenchTime-RLoopOverhead;
  107.     WriteLn('Benchmark times in seconds');
  108.     WriteLn('NullTime         : ', NullTime/100:0:2);
  109.     WriteLn('BenchTime        : ', BenchTime/100:0:2);
  110.     WriteLn('Null loops       : ', NullLoops);
  111.     WriteLn('Bench loops      : ', BenchLoops);
  112.     WriteLn('LoopOverhead     : ', RLoopOverhead/100:0:2);
  113.     WriteLn('TotalTime        : ', RTotalTime/100:0:2);
  114.     WriteLn('Loops per second : ', BenchLoops/(RTotalTime/100):0:2);
  115.   END;
  116.  
  117.  
  118. (** DUMMY *********************************************************************
  119.  *
  120.  *  Synopsis:
  121.  *
  122.  *    Dummy;
  123.  *
  124.  *  Description:
  125.  *
  126.  *    Dummy is a dummy procedure used to calculate the looping overhead in a
  127.  *    benchmark.  In order to prevent it being optimised out of existence it
  128.  *    must introduce a side effect.  In this case we modify the exported
  129.  *    variable DummyVar.
  130.  *)
  131.  
  132.   PROCEDURE Dummy;
  133.   BEGIN
  134.     DummyVar := NOT DummyVar
  135.   END;
  136.  
  137. BEGIN
  138.   NullLoopTime  := MINNULLTIME*100;
  139.   BenchLoopTime := MINBENCHTIME*100;
  140.   NullLoops     := 0;
  141.   BenchLoops    := 0;
  142.   DummyVar      := TRUE;
  143. END.
  144.